﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

using SQLExecute;

public partial class list_nghiphep : System.Web.UI.Page
{
    User u = new User();
    NghiPhep n = new NghiPhep();
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
            if (Session["email"] != null && Session["fullname"] != null)
            {
                u.Email = Session["email"].ToString();
                lFullName.Text = Session["fullname"].ToString();
                n.List_Nghi_Phep(gdNghiPhep,u.Email);
                lUsername.Text = Session["username"].ToString();
            }
            else { Response.Redirect("login.aspx"); }
        
    }

    
    protected void lnkLogout_Click(object sender, EventArgs e)
    {
        Session.Clear();
        Response.Redirect("login.aspx");
    }
    protected void gdNghiPhep_CustomButtonCallback(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewCustomButtonCallbackEventArgs e)
    {
        int id = (int)gdNghiPhep.GetRowValues(e.VisibleIndex, "id");
        string strTruongPhong=(string)gdNghiPhep.GetRowValues(e.VisibleIndex, "dv");
        DateTime dt = (DateTime)gdNghiPhep.GetRowValues(e.VisibleIndex, "nghipheptungay"); ;
        string sql = string.Empty;
        if (e.ButtonID == "btnDelete" && dt>DateTime.Now && strTruongPhong=="Chờ")
        {
            sql = "update tbl_nghiphep set active=0 where id='" + id + "'";
            SqlHelper.ExecuteNonQuery(Common.strConnect, CommandType.Text, sql);
            n.List_Nghi_Phep(gdNghiPhep,u.Email);
        }
        if (e.ButtonID == "btnEdit" && dt > DateTime.Now && strTruongPhong == "Chờ")        
            Response.RedirectLocation = "edit_form_phep.aspx?id=" + id;
        
    }
}
